package com.li.o2oSystem.util;

import javax.servlet.http.HttpServletRequest;
/**
 * 获取前台参数工具类
 * @author Administrator
 *
 */
public class HttpServletRequestUtil {
	//将获取的参数转换为整型
	public static int getInt(HttpServletRequest request,String key){
		try {
			return Integer.decode(request.getParameter(key));//decide();将String解码为Integer 

		} catch (Exception e) {
			return -1;
		}
	}
	//将获取的参数转换为长整型
	public static long getLong(HttpServletRequest request,String key){
		try {
			return Long.valueOf(request.getParameter(key));
		} catch (Exception e) {
			return -1L;
		}
	}
	//将获取的参数转换为双精度
	public static Double getDouble(HttpServletRequest request,String key){
		try {
			return Double.valueOf(request.getParameter(key));
		} catch (Exception e) {
			return -1d;
		}
	}
	//将获取的参数转换为布尔型
	public static boolean getBoolean(HttpServletRequest request,String key){
		try {
			return Boolean.valueOf(request.getParameter(key)); 
		} catch (Exception e) {
			return false;
		}
	}
	//将获取的参数转换为字符串
	public static String getString(HttpServletRequest request,String key){
		try {
			String result = request.getParameter(key);
			if(result != null){
				result.trim();//去除左右两侧的空格
				return result;
			}
			if(result.equals("")){
				return null;
			}
			return null;
		} catch (Exception e) {
			return null;
		}
	}
}
